home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume90
/
comm
/
dnet
/
dnet_213
/
part04
< prev
next >
Wrap
Text File
|
1990-03-27
|
62KB
|
2,812 lines
Path: xanth!cs.odu.edu!Amiga-Request
From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
Newsgroups: comp.sources.amiga
Subject: v90i121: DNet 2.13 - multiple windows/file transfers over a serial line, Part04/08
Message-ID: <11941@xanth.cs.odu.edu>
Date: 27 Mar 90 01:20:29 GMT
Sender: tadguy@cs.odu.edu
Reply-To: dales%teksce.sce.tek.com@RELAY.CS.NET
Lines: 2798
Approved: tadguy@cs.odu.edu (Tad Guy)
X-Mail-Submissions-To: Amiga@cs.odu.edu
X-Post-Discussions-To: comp.sys.amiga
Submitted-by: dales%teksce.sce.tek.com@RELAY.CS.NET
Posting-number: Volume 90, Issue 121
Archive-name: comm/dnet/dnet-2.13/part04
#!/bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 4 (of 8)."
# Contents: amiga/client/loadav.c amiga/dnet/packet.c
# amiga/server/sterm.c unix/client/getfiles.c unix/dnet/dnet.c
# unix/dnet/dnet.h unix/dnet/packet.c unix/lib/dnetlib.c
# Wrapped by tadguy@xanth on Mon Mar 26 20:15:13 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'amiga/client/loadav.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'amiga/client/loadav.c'\"
else
echo shar: Extracting \"'amiga/client/loadav.c'\" \(6227 characters\)
sed "s/^X//" >'amiga/client/loadav.c' <<'END_OF_FILE'
X
X/*
X * LOADAV.C
X *
X * DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
X *
X * LOADAV [frequency] Connect to remote UNIX system and display
X * load average. Default is every 5 minutes.
X *
X * frequency in seconds, default is every 60 seconds
X *
X */
X
X#include "defs.h"
X#include <local/deemu.h>
X
Xint __stdargs CXBRK(void);
X
Xshort Deemu[] = {
X DMSTRT, 0, 0,
X DMNW , 0, 10, 2, 2, -80, 40, 0xFFFF,
X DMEND , 0, 0
X};
X
X#define DMNWOFF 4
X
X#define NA 0
X#define GWIDTH (sizeof(Graph)/sizeof(Graph[0]))
X#define GDEPTH (sizeof(GMap)/sizeof(GMap[0]))
X#define GMASK (GWIDTH-1)
X
Xuword GMax[] = { 2*256, 50 };
Xuword GIncr[]= { 2*256, 20 };
Xuword GMap[2] = { 0, 1 };
Xuword Graph[1024][GDEPTH]; /* 5Min,#users. */
Xuword Gi;
X
Xubyte Scr[128];
Xubyte Initial;
X
Xubyte Title[128];
X
Xextern void updatewindow();
X
XNW Nw = {
X 0, 0, 320, 50, -1, -1,
X NEWSIZE|CLOSEWINDOW,
X WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|NOCAREREFRESH,
X NULL, NULL, Title, NULL, NULL,
X 32, 18, -1, -1, WBENCHSCREEN
X};
X
XWIN *Win;
XRP *Rp;
X
Xextern int Enable_Abort;
X
Xstruct IntuitionBase *IntuitionBase;
Xstruct GfxBase *GfxBase;
X
Xvoid clearwindow ARGS((void));
Xvoid updatewindow ARGS((char *));
Xvoid main ARGS((int, char **));
X
Xint
Xbrk()
X{
X return(0);
X}
X
Xvoid
Xmain(ac,av)
Xchar *av[];
X{
X void *chan = NULL;
X short numsecs = 60;
X long imask, tmask, dmask, mask;
X char notdone = 1;
X char *host = NULL;
X PORT *TimPort = CreatePort(NULL, 0);
X IOT Iot;
X
X onbreak(brk);
X sprintf(Title, "LoadAv V%s%s", VERSION, LOADAV_VERSION);
X {
X short i;
X for (i = 1; i < ac; ++i) {
X if (strncmp(av[i], "-N", 2) == 0) {
X host = av[i]+2;
X continue;
X }
X numsecs = atoi(av[i]);
X }
X }
X
X
X Iot.tr_node.io_Device = NULL;
X
X if (OpenDevice("timer.device", UNIT_VBLANK, (IOR *)&Iot, 0))
X goto fail;
X Iot.tr_node.io_Command = TR_ADDREQUEST;
X Iot.tr_node.io_Message.mn_ReplyPort = TimPort;
X Iot.tr_time.tv_micro = 1;
X Iot.tr_time.tv_secs = 0;
X SendIO((IOR *)&Iot);
X
X#ifndef LATTICE
X Enable_Abort = 0;
X#endif
X IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
X GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
X
X chan = DOpen(host, PORT_LOADAV, 25, 25);
X if (chan == NULL) {
X puts("no connect");
X goto fail;
X }
X InitDeemuNW(Deemu+DMNWOFF, &Nw);
X Win = OpenWindow(&Nw);
X if (Win == NULL) {
X puts("Unable to open window");
X goto fail;
X }
X Rp = Win->RPort;
X imask = 1 << Win->UserPort->mp_SigBit;
X dmask = 1 << ((PORT *)chan)->mp_SigBit;
X tmask = 1 << TimPort->mp_SigBit;
X
X clearwindow();
X while (notdone) {
X mask = Wait(imask|dmask|tmask|SIGBREAKF_CTRL_C);
X if (mask & SIGBREAKF_CTRL_C)
X notdone = 0;
X if (mask & imask) {
X IMESS *im;
X while (im = (IMESS *)GetMsg(Win->UserPort)) {
X switch(im->Class) {
X case NEWSIZE:
X clearwindow();
X break;
X case CLOSEWINDOW:
X notdone = 0;
X break;
X }
X ReplyMsg((MSG *)im);
X }
X }
X if (mask & dmask) {
X char dummy;
X if ((dummy = DNRead(chan, &dummy, 1)) != 0)
X notdone = 0;
X }
X while (mask & tmask) { /* while just so we can break */
X char len = 0;
X
X if (GetMsg(TimPort)) {
X Iot.tr_time.tv_micro = 0;
X Iot.tr_time.tv_secs = numsecs;
X SendIO((IOR *)&Iot);
X if (DWrite(chan, &len, 1) == 1 && DRead(chan, &len, 1) == 1) {
X if (len < sizeof(Title) && DRead(chan, Title, len) == len) {
X Title[len] = 0;
X updatewindow(Title);
X SetWindowTitles(Win, Title, (char *)-1);
X break;
X }
X }
X notdone = 0;
X }
X break;
X }
X }
X
Xfail:
X if (Iot.tr_node.io_Device) {
X AbortIO((IOR *)&Iot);
X WaitIO((IOR *)&Iot);
X CloseDevice((IOR *)&Iot);
X }
X DeletePort(TimPort);
X if (Win)
X CloseWindow(Win);
X if (chan)
X DClose(chan);
X if (IntuitionBase)
X CloseLibrary((LIB *)IntuitionBase);
X if (GfxBase)
X CloseLibrary((LIB *)GfxBase);
X}
X
X/*
X * Graphics routines. ************************************************
X */
X
Xshort WOx, WOy, Ww, Wh;
X
Xvoid
Xclearwindow()
X{
X short i, j, d;
X
X WOx = Win->BorderLeft;
X WOy = Win->BorderTop;
X Ww = Win->Width - Win->BorderRight - Win->BorderLeft;
X Wh = Win->Height- Win->BorderTop - Win->BorderBottom;
X
X SetAPen(Rp, 0);
X RectFill(Rp, WOx, WOy, Ww + WOx, Wh + WOy);
X WOx += 2;
X WOy += 2;
X Ww -= 4;
X Wh -= 4;
X
X /*
X * Redraw the graph. Scale values relative to GMax[?] and Wh.
X *
X * ypos = (WOy + Wh) - (Wh * value / GMax[d])
X *
X */
X
X for (d = 0; d < GDEPTH; ++d) {
X char move = 1;
X SetAPen(Rp, (d & 1) ? 3 : 1);
X for (i = Ww - 1, j = Gi - 1; i >= 0; --i, --j) {
X uword value = Wh * Graph[j&GMASK][d] / GMax[GMap[d]];
X (move) ?
X Move(Rp, WOx + i, WOy + Wh - value - 1) :
X Draw(Rp, WOx + i, WOy + Wh - value - 1)
X ;
X move = 0;
X }
X }
X}
X
X/*
X * 5:44pm up 2 days, 22:30, 37 users, load average: 5.98, 7.93, 7.97
X * 7 mins,
X */
X
Xvoid
Xupdatewindow(str)
Xchar *str;
X{
X short d;
X char refresh = 0;
X uword ary[GDEPTH];
X
X {
X long nusers, i1, f1, i5, f5;
X char *ptr = str;
X
X while (strncmp(ptr, "users", 5) && *ptr)
X ++ptr;
X while (*--ptr == ' ' && ptr != str)
X --ptr;
X while (*--ptr != ' ' && ptr != str)
X --ptr;
X nusers = atoi(ptr+1);
X while (strncmp(ptr, "load", 4) && *ptr)
X ++ptr;
X sscanf(ptr, "load average: %ld.%ld, %ld.%ld,",
X &i1, &f1, &i5, &f5
X );
X /*
X ary[0] = (i1 << 8) | ((f1 << 8) / 100);
X */
X ary[0] = (i5 << 8) | ((f5 << 8) / 100);
X ary[1] = nusers;
X }
X for (d = 0; d < GDEPTH; ++d) {
X while (ary[d] > GMax[GMap[d]] && ary[d] < 65000) {
X GMax[GMap[d]] += GIncr[GMap[d]];
X refresh = 1;
X }
X Graph[Gi][d] = ary[d];
X }
X if (!Initial) {
X short i;
X Initial = 1;
X for (i = 0; i < GWIDTH; ++i) {
X for (d = 0; d < GDEPTH; ++d)
X Graph[i][d] = Graph[Gi][d];
X }
X }
X Gi = (Gi + 1) & GMASK;
X if (refresh) {
X clearwindow();
X return;
X }
X ScrollRaster(Rp, 1, 0, WOx, WOy, WOx + Ww - 1, WOy + Wh - 1);
X for (d = 0; d < GDEPTH; ++d) {
X uword value1 = Wh * Graph[(Gi-2)&GMASK][d] / GMax[GMap[d]];
X uword value2 = Wh * Graph[(Gi-1)&GMASK][d] / GMax[GMap[d]];
X SetAPen(Rp, (d & 1) ? 3 : 1);
X Move(Rp, Ww + WOx - 2, WOy + Wh - value1 - 1);
X Draw(Rp, Ww + WOx - 1, WOy + Wh - value2 - 1);
X }
X}
X
END_OF_FILE
if test 6227 -ne `wc -c <'amiga/client/loadav.c'`; then
echo shar: \"'amiga/client/loadav.c'\" unpacked with wrong size!
fi
# end of 'amiga/client/loadav.c'
fi
if test -f 'amiga/dnet/packet.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'amiga/dnet/packet.c'\"
else
echo shar: Extracting \"'amiga/dnet/packet.c'\" \(6237 characters\)
sed "s/^X//" >'amiga/dnet/packet.c' <<'END_OF_FILE'
X
X/*
X * PACKET.C
X */
X
X#include "dnet.h"
X
Xvoid BuildPacket();
X
X#define Ascize(foo) (((foo) & 0x3F) | 0x40)
X
Xubyte RxTmp[MAXPACKET];
X
Xvoid
XBuildDataPacket(pkt, win, dbuf, actlen)
XPKT *pkt;
Xubyte win;
Xubyte *dbuf;
Xuword actlen;
X{
X ubyte *ptr;
X ubyte *pend;
X ubyte range = 0;
X static ubyte BadCtl[32] = {
X 1, 1, 1, 1, 1, 1, 1, 1,
X 1, 1, 1, 1, 1, 1, 1, 1,
X 1, 1, 1, 1, 1, 1, 1, 1,
X 1, 1, 1, 1, 1, 1, 1, 1
X };
X
X ptr = dbuf;
X pend= dbuf + actlen;
X
X while (ptr < pend) {
X if (*ptr < 0x20 && BadCtl[*ptr])
X range |= 1;
X if (*ptr >= 0x80)
X range |= 2;
X ++ptr;
X }
X if (Mode7 && range) {
X uword buflen = Expand6(dbuf, pkt->data, actlen);
X BuildPacket(pkt, PKCMD_WRITE6, win, pkt->data, actlen, buflen);
X } else {
X if (Mode7 || (range & 2)) {
X BuildPacket(pkt, PKCMD_WRITE, win, dbuf, actlen, actlen);
X } else {
X uword buflen = Compress7(dbuf, pkt->data, actlen);
X BuildPacket(pkt, PKCMD_WRITE7, win, pkt->data, actlen, buflen);
X }
X }
X}
X
XPKT *
XBuildRestartAckPacket(dbuf, bytes)
Xubyte *dbuf;
Xubyte bytes;
X{
X static PKT pkt;
X BuildPacket(&pkt, PKCMD_ACKRSTART, 0, dbuf, bytes, bytes);
X return(&pkt);
X}
X
Xvoid
XBuildPacket(pkt, ctl, win, dbuf, actlen, buflen)
XPKT *pkt;
Xubyte ctl;
Xubyte *dbuf;
Xuword actlen;
Xuword buflen;
X{
X pkt->buflen = buflen;
X pkt->sync = SYNC;
X pkt->ctl = ctl | win;
X pkt->cchk = Ascize((pkt->sync << 1) ^ pkt->ctl);
X if (actlen) {
X uword chk = chkbuf(dbuf, buflen);
X ubyte dchkh = chk >> 8;
X ubyte dchkl = chk;
X
X pkt->lenh = Ascize(actlen >> 6);
X pkt->lenl = Ascize(actlen);
X pkt->dchkh= Ascize(dchkh);
X pkt->dchkl= Ascize(dchkl);
X if (dbuf != pkt->data)
X BMov(dbuf, pkt->data, buflen);
X }
X}
X
Xvoid
XWritePacket(pkt)
XPKT *pkt;
X{
X if (DDebug)
X printf("SEND-PACKET %02x %d\n", pkt->ctl, pkt->buflen);
X
X switch(pkt->ctl & PKF_MASK) {
X case PKCMD_WRITE:
X ++Packets8Out;
X break;
X case PKCMD_WRITE6:
X ++Packets6Out;
X break;
X case PKCMD_WRITE7:
X ++Packets7Out;
X break;
X }
X
X if (pkt->buflen)
X NetWrite(&pkt->sync, 7 + pkt->buflen);
X else
X NetWrite(&pkt->sync, 3);
X}
X
Xvoid
XWriteCtlPacket(ctl, win)
X{
X static CTLPKT pkt;
X
X NetWrite(NULL, 0);
X BuildPacket(&pkt, ctl, win, NULL, 0, 0);
X WritePacket(&pkt);
X}
X
Xvoid
XWriteNak(win)
X{
X WriteCtlPacket(PKCMD_NAK, win);
X}
X
Xvoid
XWriteAck(win)
X{
X WriteCtlPacket(PKCMD_ACK, win);
X}
X
Xvoid
XWriteChk(win)
X{
X WriteCtlPacket(PKCMD_CHECK, win);
X}
X
Xvoid
XWriteRestart()
X{
X WriteCtlPacket(PKCMD_RESTART, 0);
X}
X
X/*
X * RECEIVE A PACKET
X */
X
Xint
XRecvPacket(ptr, len)
Xubyte *ptr;
Xlong len;
X{
X static uword ActLen; /* actual # bytes after decoding */
X static uword BufLen; /* length of input data buffer */
X static uword DBLen; /* # bytes already in i.d.buf */
X static ubyte RState;
X static PKT Pkt;
X ubyte *dptr;
X short expect;
X
X if (ptr == NULL) {
X RState = 0;
X return(3);
X }
X
X while (len) {
X switch(RState) {
X case 0:
X --len;
X Pkt.sync = *ptr++;
X
X if (Pkt.sync == SYNC)
X ++RState;
X break;
X case 1: /* CTL */
X --len;
X Pkt.ctl = *ptr++;
X
X if (Pkt.ctl < 0x20 || Pkt.ctl > 0x7F) {
X RState = 0;
X break;
X }
X ++RState;
X break;
X case 2: /* CCHK */
X --len;
X Pkt.cchk = *ptr++;
X
X if (Ascize((SYNC<<1) ^ Pkt.ctl) != Pkt.cchk) {
X RState = 0;
X break;
X }
X switch(Pkt.ctl & PKF_MASK) {
X case PKCMD_ACKRSTART:
X case PKCMD_WRITE:
X case PKCMD_WRITE6:
X case PKCMD_WRITE7:
X ++RState;
X break;
X default:
X do_cmd(Pkt.ctl, NULL, 0);
X RState = 0;
X break;
X }
X break;
X case 3: /* LENH */
X --len;
X Pkt.lenh = *ptr++;
X
X ++RState;
X if (Pkt.lenh < 0x20 || Pkt.lenh > 0x7F)
X RState = 0;
X break;
X case 4: /* LENL */
X --len;
X Pkt.lenl = *ptr++;
X
X if (Pkt.lenl < 0x20 || Pkt.lenl > 0x7F) {
X RState = 0;
X break;
X }
X
X ++RState;
X
X ActLen = ((Pkt.lenh & 0x3F) << 6) | (Pkt.lenl & 0x3F);
X DBLen = 0;
X
X switch(Pkt.ctl & PKF_MASK) {
X case PKCMD_ACKRSTART:
X case PKCMD_WRITE:
X BufLen = ActLen;
X break;
X case PKCMD_WRITE6:
X BufLen = (ActLen * 8 + 5) / 6;
X break;
X case PKCMD_WRITE7:
X BufLen = (ActLen * 7 + 7) / 8;
X break;
X default:
X puts("BaD");
X break;
X }
X
X if (ActLen > MAXPKT || BufLen > MAXPACKET) {
X if (PDebug || DDebug)
X printf("Packet Length Error %d %d\n", ActLen, BufLen);
X RState = 0;
X }
X break;
X case 5: /* DChkH */
X --len;
X Pkt.dchkh = *ptr++;
X
X ++RState;
X if (Pkt.dchkh < 0x20 || Pkt.dchkh > 0x7F)
X RState = 0;
X break;
X case 6: /* DCHKL */
X --len;
X Pkt.dchkl = *ptr++;
X
X ++RState;
X if (Pkt.dchkl < 0x20 || Pkt.dchkl > 0x7F)
X RState = 0;
X break;
X case 7: /* -DATA- */
X if (DBLen + len < BufLen) { /* not enough */
X BMov(ptr, Pkt.data + DBLen, len);
X DBLen += len;
X len = 0;
X break;
X }
X
X /*
X * Enough data, check chk
X */
X
X BMov(ptr, Pkt.data + DBLen, BufLen - DBLen);
X len -= BufLen - DBLen;
X ptr += BufLen - DBLen;
X
X {
X uword chk;
X ubyte chkh;
X ubyte chkl;
X
X chk = chkbuf(Pkt.data, BufLen);
X chkh = Ascize(chk >> 8);
X chkl = Ascize(chk);
X
X if (Pkt.dchkh != chkh || Pkt.dchkl != chkl) {
X printf("Chksum failure %02x %02x %02x %02x\n",
X Pkt.dchkh, chkh, Pkt.dchkl, chkl
X );
X RState = 0;
X break;
X }
X }
X
X switch(Pkt.ctl & PKF_MASK) {
X case PKCMD_ACKRSTART:
X dptr = Pkt.data;
X break;
X case PKCMD_WRITE:
X dptr = Pkt.data;
X ++Packets8In;
X break;
X case PKCMD_WRITE6:
X UnExpand6(Pkt.data, RxTmp, ActLen);
X dptr = RxTmp;
X ++Packets6In;
X break;
X case PKCMD_WRITE7:
X UnCompress7(Pkt.data, RxTmp, ActLen);
X dptr = RxTmp;
X ++Packets7In;
X break;
X default:
X puts("BaD2");
X dptr = Pkt.data;
X break;
X }
X
X do_cmd(Pkt.ctl, dptr, ActLen);
X
X RState = 0;
X break;
X }
X }
X
X {
X static short ExpAry[] = { 3, 2, 1, 4, 3, 2, 1, 0 };
X
X expect = ExpAry[RState];
X
X if (RState == 7)
X expect = BufLen - DBLen;
X }
X if (Rto_act) {
X AbortIO((IOR *)&Rto);
X WaitIO((IOR *)&Rto);
X Rto_act = 0;
X }
X if (RState == 7) {
X Rto.tr_time.tv_secs = 8;
X Rto.tr_time.tv_micro= 0;
X SendIO((IOR *)&Rto);
X Rto_act = 1;
X }
X do_cmd((uword)-1, NULL, 0);
X return((int)expect);
X}
X
END_OF_FILE
if test 6237 -ne `wc -c <'amiga/dnet/packet.c'`; then
echo shar: \"'amiga/dnet/packet.c'\" unpacked with wrong size!
fi
# end of 'amiga/dnet/packet.c'
fi
if test -f 'amiga/server/sterm.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'amiga/server/sterm.c'\"
else
echo shar: Extracting \"'amiga/server/sterm.c'\" \(6678 characters\)
sed "s/^X//" >'amiga/server/sterm.c' <<'END_OF_FILE'
X
X/*
X * S_TERM.C
X *
X * DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
X *
X * Terminal window server.
X * -Echo what is received in the window.
X * -Transmit stuff typed on keyboard, echoing locally.
X *
X * Use FTERM on the other Amiga to connect.
X *
X * NOTE!!!! Spawned tasks are ... TASKS, not processes. No DOS calls
X * allowed.
X */
X
X#include "defs.h"
X
Xint NHandlers;
X
Xstruct IntuitionBase *IntuitionBase;
Xstruct GfxBase *GfxBase;
X
XPORT *HdPort;
XPORT *LisPort;
Xshort HandShakeSig;
X
Xint spawn_handler ARGS((void));
Xvoid __saveds term_task ARGS((void));
Xvoid HandleIoctl ARGS((short, short, char, WIN *, IOCON *, short*));
Xvoid setsize ARGS((IOCON *, void *, WIN *));
X
Xint
Xbrk()
X{
X return(0);
X}
X
Xvoid
X#ifdef LATTICE
X_main(str)
X#else
X_main(len,str)
X#endif
Xchar *str;
X{
X MSG *msg;
X long mask, pmask, hdmask;
X PROC *proc = (PROC *)FindTask(NULL);
X
X onbreak(brk);
X
X if (strncmp(str, "__dnet", 6) != 0) {
X Version("STerm", VERSION, STERM_VERSION);
X _exit(0);
X }
X
X LisPort= DListen(PORT_IALPHATERM);
X WaitPort(&proc->pr_MsgPort);
X ReplyMsg(GetMsg(&proc->pr_MsgPort));
X if (!LisPort)
X exit(1);
X HdPort = CreatePort(NULL, 0);
X HandShakeSig = AllocSignal(-1);
X pmask = 1 << LisPort->mp_SigBit;
X hdmask= 1 << HdPort->mp_SigBit;
X
X IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
X GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
X while (mask = Wait(SIGBREAKF_CTRL_C|pmask|hdmask)) {
X if (mask & SIGBREAKF_CTRL_C)
X break;
X if (mask & hdmask) {
X while (msg = GetMsg(HdPort)) {
X --NHandlers;
X FreeMem(msg, sizeof(*msg));
X }
X }
X if (mask & pmask) {
X while (spawn_handler())
X ;
X }
X }
X DUnListen(LisPort);
X while (NHandlers) {
X WaitPort(HdPort);
X msg = GetMsg(HdPort);
X FreeMem(msg, sizeof(*msg));
X --NHandlers;
X }
X DeletePort(HdPort);
X CloseLibrary((LIB *)IntuitionBase);
X CloseLibrary((LIB *)GfxBase);
X}
X
X/*
X * Spawn a handler to accept the new connection, if any. Task sends
X * a message to HdPort when through.
X */
X
Xint
Xspawn_handler()
X{
X long oldhan = NHandlers;
X
X CreateTask("Term.channel", 0, (APTR)term_task, 2048);
X Wait(1 << HandShakeSig);
X return (oldhan != NHandlers);
X}
X
Xstatic NW Nw = {
X 64, 64, 400, 100, -1, -1,
X CLOSEWINDOW|NEWSIZE,
X WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|ACTIVATE|NOCAREREFRESH,
X NULL, NULL, (unsigned char *)"DNET-Term", NULL, NULL, 32, 32, -1, -1,
X WBENCHSCREEN
X};
X
Xvoid __saveds
Xterm_task()
X{
X void *chan;
X long imask, cmask, conmask;
X WIN *win;
X char notdone = 1;
X short ignorens = 0;
X char conc[4];
X IOCON iocw;
X IOCON iocr;
X
X#ifndef LATTICE
X geta4();
X#endif
X chan = DAccept(LisPort);
X if (chan) {
X DQueue(chan, 32);
X DIoctl(chan, CIO_MODE, 7, 0);
X ++NHandlers;
X Signal(HdPort->mp_SigTask, 1 << HandShakeSig);
X if (win = OpenWindow(&Nw)) {
X iocw.io_Command = CMD_WRITE;
X iocw.io_Data = (APTR)win;
X iocw.io_Message.mn_Node.ln_Type = NT_MESSAGE;
X iocw.io_Message.mn_ReplyPort = CreatePort(NULL,0);
X conmask = 1 << iocw.io_Message.mn_ReplyPort->mp_SigBit;
X OpenDevice("console.device", 0, &iocw, 0);
X iocr = iocw;
X iocr.io_Command = CMD_READ;
X imask = 1 << win->UserPort->mp_SigBit;
X cmask = 1 << ((PORT *)chan)->mp_SigBit;
X
X iocr.io_Data = (APTR)conc;
X iocr.io_Length = sizeof(conc);
X SendIO(&iocr);
X
X setsize(&iocw, NULL, win);
X while (notdone) {
X long mask;
X mask = Wait(imask|cmask|conmask);
X
X if (mask & imask) {
X IMESS *im;
X while (im = (IMESS *)GetMsg(win->UserPort)) {
X switch(im->Class) {
X case CLOSEWINDOW:
X notdone = 0;
X break;
X case NEWSIZE:
X if (ignorens) {
X --ignorens;
X setsize(&iocw, NULL, win);
X } else {
X setsize(&iocw, chan, win);
X }
X break;
X }
X ReplyMsg((MSG *)im);
X }
X }
X if ((mask & conmask) && CheckIO(&iocr)) {
X short i;
X char *ptr;
X WaitIO(&iocr);
X ptr = (char *)iocr.io_Data;
X
X if (iocr.io_Actual > 0) {
X for (i = 0; i < iocr.io_Actual; ++i) {
X if (ptr[i] == 13)
X ptr[i] = 10;
X }
X DWrite(chan, ptr, i);
X iocw.io_Data = (APTR)ptr;
X iocw.io_Length = i;
X DoIO(&iocw);
X }
X iocr.io_Data = (APTR)conc;
X iocr.io_Length = sizeof(conc);
X SendIO(&iocr);
X }
X if (mask & cmask) {
X long n;
X char buf[32];
X while (n = DNRead(chan, buf, sizeof(buf))) {
X if (n == -2) {
X short cmd, val;
X char aux;
X cmd = DGetIoctl(chan, &val, &aux);
X if (cmd >= 0)
X HandleIoctl(cmd, val, aux, win, &iocw, &ignorens);
X continue;
X }
X if (n < 0) {
X notdone = 0;
X break;
X }
X if (buf[0] == 3) /* remote ^C -- done */
X notdone = 0;
X iocw.io_Data = (APTR)buf;
X iocw.io_Length = n;
X DoIO(&iocw);
X }
X }
X }
X AbortIO(&iocr);
X WaitIO(&iocr);
X CloseDevice(&iocw);
X DeletePort(iocw.io_Message.mn_ReplyPort);
X CloseWindow(win);
X }
X DClose(chan);
X {
X MSG *msg;
X msg = AllocMem(sizeof(MSG), MEMF_PUBLIC);
X Forbid();
X PutMsg(HdPort, msg);
X }
X } else {
X Forbid();
X Signal(HdPort->mp_SigTask, 1 << HandShakeSig);
X }
X RemTask(NULL);
X}
X
Xvoid
XHandleIoctl(cmd, val, aux, win, iocw, igns)
Xshort cmd, val;
Xchar aux;
XWIN *win;
XIOCON *iocw;
Xshort *igns;
X{
X static short saverows;
X short height, width;
X short dx, dy;
X
X switch(cmd) {
X case CIO_SETROWS:
X saverows = val;
X break;
X case CIO_SETCOLS:
X width = val * win->RPort->TxWidth + win->BorderLeft + win->BorderRight;
X height= saverows * win->RPort->TxHeight + win->BorderTop + win->BorderBottom;
X
X dx = win->WScreen->Width - (win->LeftEdge + width);
X if (dx > 0)
X dx = 0;
X if (-dx > win->LeftEdge) {
X dx = -win->LeftEdge;
X width = win->WScreen->Width;
X }
X
X dy = win->WScreen->Height - (win->TopEdge + height);
X if (dy > 0)
X dy = 0;
X if (-dy > win->TopEdge) {
X dy = -win->TopEdge;
X height = win->WScreen->Height;
X }
X
X if (dx || dy) {
X MoveWindow(win, dx, dy);
X }
X if (win->Width != width || win->Height != height) {
X SizeWindow(win, width - win->Width, height - win->Height);
X ++*igns;
X }
X break;
X }
X}
X
Xvoid
Xsetsize(iocw, chan, win)
XIOCON *iocw;
Xvoid *chan;
XWIN *win;
X{
X struct ConUnit *cu = (struct ConUnit *)iocw->io_Unit;
X static char Term[64];
X
X iocw->io_Data = (APTR)"\033c\033[20h\033[t\033[u";
X iocw->io_Length = 13;
X DoIO(iocw);
X if (chan) {
X DIoctl(chan, CIO_SETROWS, (uword)(cu->cu_YMax+1), 0);
X DIoctl(chan, CIO_SETCOLS, (uword)(cu->cu_XMax+1), 0);
X }
X sprintf(Term, "STERM %ld x %ld", cu->cu_YMax+1, cu->cu_XMax+1);
X SetWindowTitles(win, Term, (char *)-1);
X}
X
END_OF_FILE
if test 6678 -ne `wc -c <'amiga/server/sterm.c'`; then
echo shar: \"'amiga/server/sterm.c'\" unpacked with wrong size!
fi
# end of 'amiga/server/sterm.c'
fi
if test -f 'unix/client/getfiles.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'unix/client/getfiles.c'\"
else
echo shar: Extracting \"'unix/client/getfiles.c'\" \(7606 characters\)
sed "s/^X//" >'unix/client/getfiles.c' <<'END_OF_FILE'
X
X/*
X * GETFILES.C V1.30
X *
X * DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
X *
X * GETFILES [-dlocaldir] [-c] file/dir file/dir file/dir
X *
X * -dlocaldir local directory to place files
X *
X * -c Continue from where you left off before. Files that already
X * exist on the local machine will not be re-transfered. This
X * will also re-start in the middle of a file that was
X * partially transfered previously.
X *
X * This command assumes the file(s) on both machines have not
X * been modified since the first attempt. No other checking
X * is done at the moment.
X */
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/file.h>
X#include <sys/stat.h>
X#include "../server/servers.h"
X
Xtypedef unsigned char ubyte;
X
Xtypedef struct {
X char Cmd;
X char Str[64];
X long Val;
X} HDR;
X
Xchar *NSpaces();
X
Xchar Buf[1024];
X
Xshort ContMode;
Xchar *NetId;
Xlong Chan = -1;
X
Xmain(ac,av)
Xchar *av[];
X{
X HDR Hdr;
X short error;
X
X {
X char *ldir = ".";
X struct stat stat;
X ac = DoOption(ac, av, "N%sd%sc", &NetId, &ldir, &ContMode);
X if (ac <= 1) {
X puts("GETFILES [-Nnetid -dlocaldir -c] remotefile/dir ...");
X fail(22);
X }
X if (chdir(ldir) < 0) {
X mkdir(ldir, 0777);
X if (chdir(ldir) < 0) {
X printf("Unable to CD or make local directory: \"%s\"\n",ldir);
X fail(21);
X }
X }
X }
X Chan = DOpen(NetId, PORT_GFILECOPY, 126, -80);
X if (Chan < 0) {
X puts("Unable to connect");
X fail(20);
X }
X error = WriteHeader('H', "Hello, getfiles client V1.30", 0);
X if (error)
X fail(LostChannel());
X switch(ReadHeader(&Hdr)) {
X case -1:
X fail(LostChannel());
X case 'H':
X printf("%s\n", Hdr.Str);
X break;
X }
X {
X register short i;
X long val;
X
X for (i = 1; i < ac; ++i) {
X short error;
X
X error = WriteHeader('G', av[i], 0);
X if (error)
X fail(LostChannel());
X switch(ReadHeader(&Hdr)) {
X case -1:
X fail(LostChannel());
X case 'N':
X printf("Remote error on %s: %s\n", av[i], Hdr.Str);
X break;
X case 'F':
X error = CheckNoPath(Hdr.Str);
X if (!error) {
X char svpath[1024];
X getwd(svpath);
X error = GetFile(&Hdr, 0);
X chdir(svpath);
X }
X break;
X case 'D':
X error = CheckNoPath(Hdr.Str);
X if (!error) {
X char svpath[1024];
X getwd(svpath);
X error = GetDir(&Hdr, 0);
X chdir(svpath);
X }
X break;
X case 'S':
X printf("Access Violation: %s\n", Hdr.Str);
X break;
X default:
X error = UnknownCmd(&Hdr);
X break;
X }
X if (error)
X fail(error);
X }
X if (!error) {
X error = WriteHeader('E', "bye", 0);
X if (error)
X fail(LostChannel());
X }
X }
X fail(0);
X}
X
Xfail(code)
X{
X if (Chan >= 0)
X close(Chan);
X exit(code);
X}
X
XCheckNoPath(str)
Xregister char *str;
X{
X while (*str) {
X if (*str == '/' || *str == ':') {
X puts("SECURITY ALERT: Illegal path spec received");
X return(40);
X }
X ++str;
X }
X return(0);
X}
X
XLostChannel()
X{
X puts("DATA CHANNEL LOST");
X return(10);
X}
X
XUnknownCmd(hdr)
XHDR *hdr;
X{
X printf("Unrecognized command code: %02x\n", hdr->Cmd);
X}
X
X/*
X * retrieve a file. If ContMode set and file exists, try to append to
X * it.
X */
X
X
X#define BSSTR "\010\010\010\010\010\010\010\010\010\010\010\010\010"
X
XGetFile(hdr, stab)
XHDR *hdr;
X{
X int fd = -1;
X long pos = 0;
X short error = 0;
X
X printf("%s%-20s ", NSpaces(stab), hdr->Str);
X fflush(stdout);
X if (ContMode) {
X if ((fd = open(hdr->Str, O_WRONLY)) >= 0) { /* already exists */
X long len;
X
X len = lseek(fd, 0L, 2);
X if (len > hdr->Val) {
X close(fd);
X printf("Cont Error, local file is larger than remote!: %s\n",
X hdr->Str
X );
X puts("(not downloaded)");
X return(0);
X }
X if (len == hdr->Val) {
X close(fd);
X if (error = WriteHeader('S', NULL, 0))
X return(LostChannel());
X puts("HAVE IT, SKIP");
X return(0);
X }
X printf("(HAVE %ld/%ld) ", len, hdr->Val);
X hdr->Val -= len; /* that much less */
X pos = len; /* start at offset */
X }
X }
X if (fd < 0) {
X fd = open(hdr->Str, O_WRONLY|O_CREAT|O_TRUNC, 0666);
X if (fd < 0) {
X error = WriteHeader('N', "open error", 0);
X printf("Unable to open %s for output\n", hdr->Str);
X if (error)
X return(LostChannel());
X return(1);
X }
X }
X error = WriteHeader('Y', NULL, pos); /* yes, gimme gimme */
X
X /*
X * Retrieve the data
X */
X
X if (!error) {
X register long left = hdr->Val;
X register long cnt = pos;
X long total = pos + left;
X
X printf(" ");
X while (left) {
X register long n = (left > sizeof(Buf)) ? sizeof(Buf) : left;
X printf("%s%6ld/%6ld", BSSTR, cnt, total);
X fflush(stdout);
X if (ggread(Chan, Buf, n) != n) {
X error = 5;
X break;
X }
X if (write(fd, Buf, n) != n) {
X puts("Local Write failed!");
X error = 6;
X break;
X }
X left -= n;
X cnt += n;
X }
X printf("%s%6ld/%6ld %s", BSSTR, cnt, total,
X ((cnt == total) ? "OK" : "INCOMPLETE")
X );
X }
X puts("");
X if (error) {
X fchmod(fd, 0222);
X close(fd);
X return(LostChannel());
X }
X close(fd);
X return(error);
X}
X
X/*
X * Retrieve a directory. Create it if necessary.
X */
X
XGetDir(hdr, stab)
XHDR *hdr;
X{
X short error = 0;
X long dirlock;
X static HDR Hdr; /* note: static */
X char svpath[1024];
X
X printf("%s%-20s(DIR)\n", NSpaces(stab), hdr->Str);
X getwd(svpath);
X if (chdir(hdr->Str) < 0) {
X mkdir(hdr->Str, 0777);
X if (chdir(hdr->Str) < 0) {
X error = WriteHeader('N', "couldn't create", 0);
X printf("Unable to create local directory: %s\n", hdr->Str);
X if (error)
X return(LostChannel());
X return(1);
X }
X }
X error = WriteHeader('Y', NULL, 0); /* yes, gimme gimme */
X while (!error) {
X switch(ReadHeader(&Hdr)) {
X case -1:
X error = 1;
X break;
X case 'E': /* end of directory */
X chdir(svpath);
X return(0);
X break;
X case 'F':
X error = CheckNoPath(Hdr.Str);
X if (!error) {
X char svpath2[1024];
X getwd(svpath2);
X error = GetFile(&Hdr, stab + 4);
X chdir(svpath2);
X }
X break;
X case 'D':
X error = CheckNoPath(Hdr.Str);
X if (!error) {
X char svpath2[1024];
X getwd(svpath2);
X error = GetDir(&Hdr, stab + 4);
X chdir(svpath2);
X }
X break;
X case 'S':
X printf("Access Violation: %s\n", Hdr.Str);
X break;
X case 'N':
X printf("REMOTE ERROR: %s\n", Hdr.Str);
X error = 10;
X break;
X default:
X error = UnknownCmd(&Hdr);
X break;
X }
X }
X chdir(svpath);
X return(LostChannel());
X}
X
XWriteHeader(c, str, len)
Xchar c;
Xchar *str;
Xlong len;
X{
X ubyte sl;
X
X if (str == NULL)
X str = "";
X sl = strlen(str);
X
X if (gwrite(Chan, &c, 1) < 0)
X return(1);
X if (gwrite(Chan, &sl,1) < 0)
X return(1);
X if (gwrite(Chan, str, sl) != sl)
X return(1);
X len = htonl68(len);
X if (gwrite(Chan, &len, 4) != 4)
X return(1);
X return(0);
X}
X
XReadHeader(hdr)
XHDR *hdr;
X{
X ubyte sl;
X ubyte cmd;
X
X hdr->Cmd = -1;
X if (ggread(Chan, &cmd, 1) != 1)
X return(-1);
X if (ggread(Chan, &sl, 1) != 1)
X return(-1);
X if (sl >= sizeof(hdr->Str)) {
X puts("Software error: received file name length too long");
X return(-1);
X }
X if (ggread(Chan, hdr->Str, sl) != sl)
X return(-1);
X hdr->Str[sl] = 0;
X if (ggread(Chan, &hdr->Val, 4) != 4)
X return(-1);
X hdr->Val = ntohl68(hdr->Val);
X hdr->Cmd = cmd;
X return(hdr->Cmd);
X}
X
Xchar *
XNSpaces(n)
Xshort n;
X{
X static char Buf[128];
X static short in = 0;
X static short last;
X
X if (in == 0) {
X register short i;
X in = 1;
X for (i = 0; i < sizeof(Buf); ++i)
X Buf[i] = ' ';
X }
X Buf[last] = ' ';
X if (n < 127)
X Buf[n] = 0;
X last = n;
X return(Buf);
X}
X
END_OF_FILE
if test 7606 -ne `wc -c <'unix/client/getfiles.c'`; then
echo shar: \"'unix/client/getfiles.c'\" unpacked with wrong size!
fi
# end of 'unix/client/getfiles.c'
fi
if test -f 'unix/dnet/dnet.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'unix/dnet/dnet.c'\"
else
echo shar: Extracting \"'unix/dnet/dnet.c'\" \(7795 characters\)
sed "s/^X//" >'unix/dnet/dnet.c' <<'END_OF_FILE'
X
X/*
X * DNET.C
X *
X * DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved
X *
X * Handles action on all active file descriptors and dispatches
X * to the proper function in FILES.C
X *
X */
X
X#include "dnet.h"
X#include <sys/wait.h>
X#include <sys/resource.h>
X#include <sys/un.h>
X
Xhandle_child()
X{
X union wait stat;
X struct rusage rus;
X while (wait3(&stat, WNOHANG, &rus) > 0);
X}
X
Xchar *
Xshowselect(ptr)
Xfd_set *ptr;
X{
X static char buf[FD_SETSIZE+32];
X short i;
X
X for (i = 0; i < FD_SETSIZE; ++i) {
X buf[i] = (FD_ISSET(i, ptr)) ? '1' : '0';
X }
X buf[i] = 0;
X return(buf);
X}
X
X
Xloganddie()
X{
X fflush(stderr);
X fprintf(stderr, "\nHUPSIGNAL\n");
X perror("HUP, last error:");
X fprintf(stderr, "Last select return:\n");
X fprintf(stderr, " %s\n", showselect(&Fdread));
X fprintf(stderr, " %s\n", showselect(&Fdwrite));
X fprintf(stderr, " %s\n", showselect(&Fdexcept));
X fprintf(stderr, "RcvData = %ld\n", RcvData);
X fprintf(stderr, "RChan/WChan = %ld/%ld\n", RChan, WChan);
X fprintf(stderr, "RPStart = %ld\n", RPStart);
X fprintf(stderr, "WPStart = %ld\n", WPStart);
X fprintf(stderr, "WPUsed = %ld\n", WPUsed);
X fprintf(stderr, "RState = %ld\n", RState);
X fflush(stderr);
X kill(0, SIGILL);
X exit(1);
X}
X
X#define SASIZE(sa) (sizeof(sa)-sizeof((sa).sa_data)+strlen((sa).sa_data))
X
Xmain(ac,av)
Xchar *av[];
X{
X long sink_mask, dnet_mask;
X ubyte notdone;
X char local_dir[MAXPATHLEN];
X struct passwd pw_info;
X extern void RcvInt();
X
X if (write(0, "", 0) < 0) {
X perror("write");
X exit(1);
X }
X
X if (getenv("DNETDIR")) {
X strcpy(local_dir, getenv("DNETDIR"));
X if (chdir(local_dir)) {
X fprintf(stderr, "Unable to chdir to DNETDIR: %s\n", local_dir);
X exit(1);
X }
X freopen("DNET.LOG", "w", stderr);
X setlinebuf(stderr);
X } else {
X pw_info = *getpwuid(getuid());
X strcpy(local_dir, pw_info.pw_dir);
X strcat(local_dir, "/.dnet");
X if (chdir(local_dir)) {
X mkdir(local_dir, 0700);
X if (chdir(local_dir)) {
X fprintf(stderr, "Unable to create dir %s\n", local_dir);
X exit(1);
X }
X }
X freopen("DNET.LOG", "w", stderr);
X }
X fprintf(stderr, "DNet startup\n");
X fprintf(stderr, "Log file placed in %s\n", local_dir);
X
X /*signal(SIGINT, SIG_IGN);*/
X signal(SIGPIPE, SIG_IGN);
X /*signal(SIGQUIT, SIG_IGN);*/
X signal(SIGCHLD, handle_child);
X signal(SIGHUP, loganddie);
X
X bzero(Pkts,sizeof(Pkts));
X setlistenport("3");
X
X {
X register short i;
X for (i = 1; i < ac; ++i) {
X register char *ptr = av[i];
X if (*ptr != '-') {
X DDebug = 1;
X fprintf(stderr, "Debug mode on\n");
X setlinebuf(stderr);
X setlinebuf(stdout);
X continue;
X }
X ++ptr;
X switch(*ptr) {
X case 'B':
X break;
X case 'm': /* Mode7 */
X Mode7 = atoi(ptr + 1);
X if (Mode7 == 0)
X fprintf(stderr, "8 bit mode selected\n");
X else
X fprintf(stderr, "7 bit mode selected\n");
X break;
X default:
X fprintf(stderr, "Unknown option: %c\n", *ptr);
X printf("Unknown option: %c\n", *ptr);
X exit(1);
X }
X }
X }
X
X NewList(&TxList);
X
X Fdperm[0] = 1;
X Fdstate[0] = RcvInt;
X FD_SET(0, &Fdread);
X FD_SET(0, &Fdexcept);
X
X fprintf(stderr, "DNET RUNNING, Listenfd=%ld\n", DNet_fd);
X NetOpen(); /* initialize network and interrupt driven read */
X TimerOpen(); /* initialize timers */
X
X do_netreset();
X do_restart();
X
X notdone = 1;
X while (notdone) {
X /*
X * MAIN LOOP. select() on all the file descriptors. Set the
X * timeout to infinity (NULL) normally. However, if there is
X * a pending read or write timeout, set the select timeout
X * to 2 seconds in case they timeout before we call select().
X * (i.e. a timing window). OR, if we are in the middle of a
X * read, don't use descriptor 0 and timeout according to
X * the expected read length, then set the descriptor as ready.
X */
X
X fd_set fd_rd;
X fd_set fd_wr;
X fd_set fd_ex;
X struct timeval tv, *ptv;
X int err;
X
X fd_rd = Fdread;
X fd_wr = Fdwrite;
X fd_ex = Fdexcept;
X
X tv.tv_sec = 0; /* normally wait forever for an event */
X tv.tv_usec= 0;
X ptv = NULL;
X if ((Rto_act || Wto_act)) { /* unless timeout pending */
X ptv = &tv;
X tv.tv_sec = 2;
X }
X
X /* ... or expecting data (don't just wait for one byte).
X *
X * This is an attempt to reduce the CPU usage for the process.
X * If we are expecting data over the serial line, then don't
X * return from the select() even if data is available, but
X * wait for the timeout period indicated before reading the
X * data. Don't wait more than 64 byte times or we may loose
X * some data (the silo's are only so big.. like 128 bytes).
X *
X * Currently we wait 1562uS/byte (1/10 second for 64 bytes)
X * This number is used simply so we don't hog the cpu reading
X * a packet.
X */
X
X if (RExpect) {
X ptv = &tv;
X tv.tv_usec= 1562L * ((RExpect < 64) ? RExpect : 64);
X tv.tv_sec = 0;
X FD_CLR(0, &fd_rd);
X }
X if (WReady) { /* transmit stage has work to do */
X ptv = &tv;
X tv.tv_usec = 0;
X tv.tv_sec = 0;
X }
X err = select(FD_SETSIZE, &fd_rd, &fd_wr, &fd_ex, ptv);
X if (RExpect) {
X FD_SET(0, &fd_rd); /* pretend data ready */
X }
X if (DDebug)
X fprintf(stderr, "SERR %ld %ld %08lx %08lx\n",
X err, errno, RExpect, ptv
X );
X
X if (RTimedout) {
X RTimedout = 0;
X do_rto();
X }
X if (WTimedout) {
X WTimedout = 0;
X Wto_act = 0;
X do_wto();
X }
X if (err < 0) {
X if (errno == EBADF) {
X perror("select");
X dneterror(NULL);
X }
X } else {
X register short i;
X register short j;
X register long mask;
X
X for (i = 0; i < FD_SETSIZE/NFDBITS; ++i) {
X if (mask = fd_ex.fds_bits[i]) {
X for (j = i * NFDBITS; mask; (mask >>= 1),(++j)) {
X if (mask & 1)
X (*Fdstate[j])(2,j);
X }
X }
X if (mask = fd_wr.fds_bits[i]) {
X for (j = i * NFDBITS; mask; (mask >>= 1),(++j)) {
X if (mask & 1)
X (*Fdstate[j])(1,j);
X }
X }
X if (mask = fd_rd.fds_bits[i]) {
X for (j = i * NFDBITS; mask; (mask >>= 1),(++j)) {
X if (mask & 1)
X (*Fdstate[j])(0,j);
X }
X }
X }
X }
X if (RcvData)
X do_rnet();
X do_wupdate();
X }
X dneterror(NULL);
X}
X
Xvoid
Xnop()
X{
X}
X
Xdo_netreset()
X{
X register short i;
X register CHAN *ch;
X for (i = 0; i < FD_SETSIZE; ++i) {
X if (!Fdperm[i])
X Fdstate[i] = nop;
X }
X for (i = 0, ch = Chan; i < MAXCHAN; ++i, ++ch) {
X switch(ch->state) {
X case CHAN_OPEN:
X case CHAN_LOPEN: /* pending on network */
X case CHAN_CLOSE:
X if (ch->fd >= 0) {
X FD_CLR(ch->fd, &Fdread);
X FD_CLR(ch->fd, &Fdexcept);
X Fdstate[ch->fd] = nop;
X close(ch->fd);
X ch->fd = -1;
X ch->state = CHAN_FREE;
X ch->flags = 0;
X --NumCon;
X }
X ClearChan(&TxList, i, 1);
X break;
X }
X }
X RPStart = 0;
X WPStart = 0;
X WPUsed = 0;
X RState = 0;
X RChan = 0;
X WChan = 0;
X}
X
Xdo_restart()
X{
X WriteRestart();
X Restart = 1;
X}
X
Xsetlistenport(remotehost)
Xchar *remotehost;
X{
X static struct sockaddr_un sa;
X int s;
X extern void do_localopen();
X
X if (DNet_fd >= 0) {
X unlink(sa.sun_path);
X Fdstate[DNet_fd] = nop;
X Fdperm[DNet_fd] = 0;
X FD_CLR(DNet_fd, &Fdread);
X FD_CLR(DNet_fd, &Fdexcept);
X close(DNet_fd);
X }
X setenv("DNETHOST=", remotehost);
X sprintf(sa.sun_path, "DNET.%s", remotehost);
X unlink(sa.sun_path);
X sa.sun_family = AF_UNIX;
X
X s = socket(PF_UNIX, SOCK_STREAM, 0);
X /* fcntl(s, F_SETOWN, getpid()); */
X fcntl(s, F_SETFL, FNDELAY);
X if (bind(s, &sa, sizeof(sa.sun_family) + strlen(sa.sun_path)) < 0) {
X perror("bind");
X exit(1);
X }
X if (listen(s, 5) < 0) {
X unlink(sa.sun_path);
X perror("listen");
X exit(1);
X }
X DNet_fd = s;
X Fdstate[DNet_fd] = do_localopen;
X Fdperm[DNet_fd] = 1;
X FD_SET(DNet_fd, &Fdread);
X FD_SET(DNet_fd, &Fdexcept);
X}
X
END_OF_FILE
if test 7795 -ne `wc -c <'unix/dnet/dnet.c'`; then
echo shar: \"'unix/dnet/dnet.c'\" unpacked with wrong size!
fi
# end of 'unix/dnet/dnet.c'
fi
if test -f 'unix/dnet/dnet.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'unix/dnet/dnet.h'\"
else
echo shar: Extracting \"'unix/dnet/dnet.h'\" \(6529 characters\)
sed "s/^X//" >'unix/dnet/dnet.h' <<'END_OF_FILE'
X
X/*
X * DNET.H
X *
X * DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved
X */
X
X#include <sys/types.h>
X#include <sys/ioctl.h>
X#include <sys/socket.h>
X#include <sys/time.h>
X#include <sys/file.h>
X
X/* V2.01 */
X#include <sys/param.h>
X#include <pwd.h>
X
X#include <signal.h>
X#include <stdio.h>
X#include <errno.h>
X#ifndef FD_SETSIZE
X#define FD_SETSIZE (sizeof(struct fd_set) * 8)
X#endif
X#ifndef NFDBITS
X#define NFDBITS 32
X#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
X#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
X#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
X#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
X#endif
X#ifndef sigmask
X#define sigmask(m) (1 << ((m)-1))
X#endif
X
X#ifndef LASTTRYDNETSERVERS
X#define LASTTRYDNETSERVERS "/usr/local/lib/dnet/dnet.servers"
X#endif
X
Xstruct Node {
X struct Node *ln_Succ;
X struct Node *ln_Pred;
X};
X
Xstruct List {
X struct Node *lh_Head;
X struct Node *lh_Tail;
X struct Node *lh_TailPred;
X};
X
X
Xtypedef unsigned char ubyte;
Xtypedef unsigned short uword;
Xtypedef unsigned long ulong;
X
Xtypedef struct List LIST;
Xtypedef struct Node NODE;
X
X#include "channel.h"
X
X#define PKT struct _PKT
X#define CTLPKT struct _CTLPKT
X#define XIOR struct _XIOR
X
X#define EMPTY 0 /* empty (sent) */
X#define READY 1 /* data ready (not sent yet) */
X#define RCVBUF 4096
X
X#define MAXCHAN 128 /* Max # of channels supported */
X#define SYNC 0x5B /* SYNC character */
X#define WTIME 8 /* in seconds (expect ack) */
X#define RTIME 4 /* in seconds (read to) */
X#define MAXPKT 200 /* maximum packet size (data area) */
X#define MINPKT 32 /* minimum packet size (data area) for purposes */
X /* of determining the dynamic maximum packet size*/
X /* only. Actual minimum is, of course, 1 byte */
X
X#define MAXPACKET ((MAXPKT * 8 + 5) / 6 + 64)
X
X#define OVERHEAD 7 /* for packets with data */
X
XXIOR {
X NODE io_Node;
X ubyte *io_Data;
X ulong io_Length;
X ulong io_Actual;
X uword io_Channel;
X ubyte io_Command;
X ubyte io_Error;
X char io_Pri;
X};
X
XPKT {
X uword buflen;
X ubyte state; /* EMPTY, READY */
X
X ubyte sync; /* THE PACKET */
X ubyte ctl;
X ubyte cchk;
X ubyte lenh;
X ubyte lenl;
X ubyte dchkh;
X ubyte dchkl;
X ubyte data[MAXPACKET];
X};
X
XCTLPKT {
X uword buflen;
X ubyte state;
X
X ubyte sync;
X ubyte ctl;
X ubyte cchk;
X};
X
X /*
X * In receiving a packet the receiver can be in one of these
X * states.
X */
X
X#define RS_SYNC 0 /* Waiting for sync */
X#define RS_CTL 1 /* Waiting for command */
X#define RS_CCHK 2 /* Waiting for check byte */
X#define RS_LEN1 3 /* Waiting for MSB length byte */
X#define RS_LEN2 4 /* Waiting for LSB length byte */
X#define RS_DATA 5 /* Waiting for data & checksum */
X
X /*
X * The low level protocol generates packets. This is used
X * for error checking, data sequencing, retries, restart, etc...
X * The packet format is:
X *
X * SYNC sss0xccc CHK
X * SYNC sss1xccc CHK nnnnnnnn nnnnnnnn [DATA] CHK2
X * msb lsb
X *
X * sss = sequence #
X * B4 = packet contains data
X * B3 = reserved (may be used to extend the command set)
X * ccc = PKF_?????
X *
X * NOTE that the data length nnn..nn is not checked with either
X * CHK or CHK2 . The protocol will determine if the length
X * is reasonable (< MAXPKT) and then try to read that many
X * bytes. The CHK will obviously fail if the length was
X * incorrect.
X */
X
X#define PKF_SEQUENCE 0x07 /* Sequence # */
X#define PKF_MASK 0x78 /* command mask */
X
X#define PKCMD_RESTART 0x20 /* RESTART dnet. (new) */
X#define PKCMD_ACKRSTART 0x28 /* ACK a restart (new) */
X#define PKCMD_WRITE6 0x30
X#define PKCMD_WRITE 0x38 /* A DATA packet */
X#define PKCMD_CHECK 0x40 /* Request ACK or NAK for win */
X#define PKCMD_ACK 0x48 /* ACK a window */
X#define PKCMD_NAK 0x50 /* NAK a window */
X#define PKCMD_WRITE7 0x58
X
X /*
X * All channel multiplexing, channel commands, etc... is encoded
X * within a PKCMD_WRITE packet.
X *
X * Channel commands are characterized by a one byte control
X * field and up to 7 bytes of data. The control field format
X * is: 10cccnnn [DATA] ccc = SCMD_??
X * nnn = # additional data bytes
X */
X
X#define SCMD_SWITCH 0x00 /* switch active channel # */
X#define SCMD_OPEN 0x01 /* open a channel */
X#define SCMD_CLOSE 0x02 /* close a channel */
X#define SCMD_ACKCMD 0x03 /* ack an open/close request */
X#define SCMD_EOFCMD 0x04 /* Reof or Weof */
X#define SCMD_QUIT 0x05 /* QUIT dnet */
X#define SCMD_IOCTL 0x06 /* channel ioctl (new),PTY sup */
X#define SCMD_RESERVE1 0x07
X
X /*
X * Stream data is characterized by the following format:
X *
X * msb lsb
X * 11nnnnnn nnnnnnnn [128-16383 bytes DATA]
X * 0nnnnnnn [0-127 bytes DATA]
X *
X * NOTE: 11000000 0ccccccc nnnnnnnn reserved for furture ext. of
X * SCMD commands.
X */
X
X#define SCMD_DATA 0x08 /* stream command, DATA (dummy ID) */
X
X /*
X * Each channel can be in one of several states.
X */
X
X#define CHAN_FREE 0x01 /* free channel */
X#define CHAN_ROPEN 0x02 /* remote open, wait port msg */
X#define CHAN_LOPEN 0x03 /* local open, wait reply */
X#define CHAN_OPEN 0x04 /* channel open */
X#define CHAN_CLOSE 0x05 /* one side of channel closed */
X
X#define CHANF_ROK 0x01 /* remote hasn't EOF'd us yet */
X#define CHANF_WOK 0x02 /* remote will accept data */
X#define CHANF_LCLOSE 0x04 /* channel closed on our side */
X#define CHANF_RCLOSE 0x08 /* channel closed on rem side */
X
Xextern ubyte *RemHead();
Xextern ubyte *malloc();
Xextern char *getenv();
X
X#ifndef NOEXT
Xextern int DNet_fd;
Xextern PKT Pkts[9];
Xextern PKT *RPak[4];
Xextern PKT *WPak[4];
Xextern CHAN Chan[MAXCHAN];
Xextern LIST TxList; /* For pending DNCMD_WRITE reqs. */
Xextern fd_set Fdread;
Xextern fd_set Fdwrite;
Xextern fd_set Fdexcept;
Xextern void (*Fdstate[FD_SETSIZE])();
Xextern ubyte Fdperm[FD_SETSIZE];
Xextern uword FdChan[FD_SETSIZE];
Xextern ubyte RcvBuf[RCVBUF];
Xextern ubyte RTimedout, WTimedout;
Xextern uword Rto_act, Wto_act;
Xextern uword RcvData;
Xextern uword RExpect;
Xextern uword RChan;
Xextern uword WChan;
Xextern uword RPStart;
Xextern uword WPStart;
Xextern uword WPUsed;
Xextern uword RState;
Xextern ubyte DDebug;
Xextern ubyte PDebug;
Xextern ubyte Restart;
Xextern ubyte DeldQuit;
Xextern ulong NumCon;
Xextern ubyte Mode7;
X
Xextern int errno;
Xextern int WReady;
X
X#endif
X
END_OF_FILE
if test 6529 -ne `wc -c <'unix/dnet/dnet.h'`; then
echo shar: \"'unix/dnet/dnet.h'\" unpacked with wrong size!
fi
# end of 'unix/dnet/dnet.h'
fi
if test -f 'unix/dnet/packet.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'unix/dnet/packet.c'\"
else
echo shar: Extracting \"'unix/dnet/packet.c'\" \(6388 characters\)
sed "s/^X//" >'unix/dnet/packet.c' <<'END_OF_FILE'
X
X/*
X * PACKET.C
X */
X
X#include "dnet.h"
X
Xvoid BuildPacket();
X
X#define Ascize(foo) (((foo) & 0x3F) | 0x40)
X
Xubyte RxTmp[MAXPACKET];
X
Xvoid
XBuildDataPacket(pkt, win, dbuf, actlen)
XPKT *pkt;
Xubyte win;
Xubyte *dbuf;
Xuword actlen;
X{
X ubyte *ptr;
X ubyte *pend;
X ubyte range = 0;
X static ubyte BadCtl[32] = {
X 1, 1, 1, 1, 1, 1, 1, 1,
X 1, 1, 1, 1, 1, 1, 1, 1,
X 1, 1, 1, 1, 1, 1, 1, 1,
X 1, 1, 1, 1, 1, 1, 1, 1
X };
X
X ptr = dbuf;
X pend= dbuf + actlen;
X
X while (ptr < pend) {
X if (*ptr < 0x20 && BadCtl[*ptr])
X range |= 1;
X if (*ptr >= 0x80)
X range |= 2;
X ++ptr;
X }
X if (Mode7 && range) {
X uword buflen = Expand6(dbuf, pkt->data, actlen);
X BuildPacket(pkt, PKCMD_WRITE6, win, pkt->data, actlen, buflen);
X } else {
X if (Mode7 || (range & 2)) {
X BuildPacket(pkt, PKCMD_WRITE, win, dbuf, actlen, actlen);
X } else {
X uword buflen = Compress7(dbuf, pkt->data, actlen);
X BuildPacket(pkt, PKCMD_WRITE7, win, pkt->data, actlen, buflen);
X }
X }
X}
X
XPKT *
XBuildRestartAckPacket(dbuf, bytes)
Xubyte *dbuf;
Xubyte bytes;
X{
X static PKT pkt;
X BuildPacket(&pkt, PKCMD_ACKRSTART, 0, dbuf, bytes, bytes);
X return(&pkt);
X}
X
Xvoid
XBuildPacket(pkt, ctl, win, dbuf, actlen, buflen)
XPKT *pkt;
Xubyte ctl;
Xubyte *dbuf;
Xuword actlen;
Xuword buflen;
X{
X pkt->buflen = buflen;
X pkt->sync = SYNC;
X pkt->ctl = ctl | win;
X pkt->cchk = Ascize((pkt->sync << 1) ^ pkt->ctl);
X if (actlen) {
X uword chk = chkbuf(dbuf, buflen);
X ubyte dchkh = chk >> 8;
X ubyte dchkl = chk;
X
X pkt->lenh = Ascize(actlen >> 6);
X pkt->lenl = Ascize(actlen);
X pkt->dchkh= Ascize(dchkh);
X pkt->dchkl= Ascize(dchkl);
X if (dbuf != pkt->data)
X bcopy(dbuf, pkt->data, buflen);
X }
X}
X
Xvoid
XWritePacket(pkt)
XPKT *pkt;
X{
X if (DDebug)
X printf("SEND-PACKET %02x %d\n", pkt->ctl, pkt->buflen);
X
X if (pkt->buflen)
X NetWrite(&pkt->sync, 7 + pkt->buflen);
X else
X NetWrite(&pkt->sync, 3);
X switch(pkt->ctl) {
X case PKCMD_WRITE:
X case PKCMD_WRITE6:
X case PKCMD_WRITE7:
X case PKCMD_RESTART:
X WTimeout(WTIME);
X }
X}
X
Xvoid
XWriteCtlPacket(ctl, win)
X{
X static CTLPKT pkt;
X
X NetWrite(NULL, 0);
X BuildPacket(&pkt, ctl, win, NULL, 0, 0);
X WritePacket(&pkt);
X}
X
Xvoid
XWriteNak(win)
X{
X WriteCtlPacket(PKCMD_NAK, win);
X}
X
Xvoid
XWriteAck(win)
X{
X WriteCtlPacket(PKCMD_ACK, win);
X}
X
Xvoid
XWriteChk(win)
X{
X WriteCtlPacket(PKCMD_CHECK, win);
X}
X
Xvoid
XWriteRestart()
X{
X WriteCtlPacket(PKCMD_RESTART, 0);
X}
X
X/*
X * RECEIVE A PACKET
X */
X
Xint
XRecvPacket(ptr, len)
Xubyte *ptr;
Xlong len;
X{
X static uword ActLen; /* actual # bytes after decoding */
X static uword BufLen; /* length of input data buffer */
X static uword DBLen; /* # bytes already in i.d.buf */
X static ubyte RState;
X static PKT Pkt;
X ubyte *dptr;
X short expect;
X
X if (ptr == NULL) {
X RState = 0;
X return(3);
X }
X
X while (len) {
X switch(RState) {
X case 0:
X --len;
X Pkt.sync = *ptr++;
X
X if (Pkt.sync == SYNC)
X ++RState;
X break;
X case 1: /* CTL */
X --len;
X Pkt.ctl = *ptr++;
X
X if (Pkt.ctl < 0x20 || Pkt.ctl > 0x7F) {
X RState = 0;
X break;
X }
X ++RState;
X break;
X case 2: /* CCHK */
X --len;
X Pkt.cchk = *ptr++;
X
X if (Ascize((SYNC<<1) ^ Pkt.ctl) != Pkt.cchk) {
X RState = 0;
X break;
X }
X switch(Pkt.ctl & PKF_MASK) {
X case PKCMD_ACKRSTART:
X case PKCMD_WRITE:
X case PKCMD_WRITE6:
X case PKCMD_WRITE7:
X if (DDebug)
X printf("Recv Header %02x\n", Pkt.ctl & PKF_MASK);
X ++RState;
X break;
X default:
X if (DDebug)
X printf("Recv Control %02x\n", Pkt.ctl & PKF_MASK);
X do_cmd(Pkt.ctl, NULL, 0);
X RState = 0;
X break;
X }
X break;
X case 3: /* LENH */
X --len;
X Pkt.lenh = *ptr++;
X
X ++RState;
X if (Pkt.lenh < 0x20 || Pkt.lenh > 0x7F)
X RState = 0;
X break;
X case 4: /* LENL */
X --len;
X Pkt.lenl = *ptr++;
X
X if (Pkt.lenl < 0x20 || Pkt.lenl > 0x7F) {
X RState = 0;
X break;
X }
X
X ++RState;
X
X ActLen = ((Pkt.lenh & 0x3F) << 6) | (Pkt.lenl & 0x3F);
X DBLen = 0;
X
X switch(Pkt.ctl & PKF_MASK) {
X case PKCMD_ACKRSTART:
X case PKCMD_WRITE:
X BufLen = ActLen;
X break;
X case PKCMD_WRITE6:
X BufLen = (ActLen * 8 + 5) / 6;
X break;
X case PKCMD_WRITE7:
X BufLen = (ActLen * 7 + 7) / 8;
X break;
X default:
X puts("BaD");
X break;
X }
X
X if (ActLen > MAXPKT || BufLen > MAXPACKET) {
X if (DDebug || DDebug)
X printf("Packet Length Error %d %d\n", ActLen, BufLen);
X RState = 0;
X }
X break;
X case 5: /* DChkH */
X --len;
X Pkt.dchkh = *ptr++;
X
X ++RState;
X if (Pkt.dchkh < 0x20 || Pkt.dchkh > 0x7F)
X RState = 0;
X break;
X case 6: /* DCHKL */
X --len;
X Pkt.dchkl = *ptr++;
X
X ++RState;
X if (Pkt.dchkl < 0x20 || Pkt.dchkl > 0x7F)
X RState = 0;
X break;
X case 7: /* -DATA- */
X if (DBLen + len < BufLen) { /* not enough */
X bcopy(ptr, Pkt.data + DBLen, len);
X DBLen += len;
X len = 0;
X break;
X }
X
X /*
X * Enough data, check chk
X */
X
X bcopy(ptr, Pkt.data + DBLen, BufLen - DBLen);
X len -= BufLen - DBLen;
X ptr += BufLen - DBLen;
X
X {
X uword chk;
X ubyte chkh;
X ubyte chkl;
X
X chk = chkbuf(Pkt.data, BufLen);
X chkh = Ascize(chk >> 8);
X chkl = Ascize(chk);
X
X if (Pkt.dchkh != chkh || Pkt.dchkl != chkl) {
X printf("Chksum failure %02x %02x %02x %02x\n",
X Pkt.dchkh, chkh, Pkt.dchkl, chkl
X );
X RState = 0;
X break;
X }
X }
X
X switch(Pkt.ctl & PKF_MASK) {
X case PKCMD_ACKRSTART:
X dptr = Pkt.data;
X break;
X case PKCMD_WRITE:
X dptr = Pkt.data;
X break;
X case PKCMD_WRITE6:
X UnExpand6(Pkt.data, RxTmp, ActLen);
X dptr = RxTmp;
X break;
X case PKCMD_WRITE7:
X UnCompress7(Pkt.data, RxTmp, ActLen);
X dptr = RxTmp;
X break;
X default:
X puts("BaD2");
X dptr = Pkt.data;
X break;
X }
X if (DDebug)
X printf("Recv Body %02x %ld bytes\n", Pkt.ctl, ActLen);
X
X do_cmd(Pkt.ctl, dptr, ActLen);
X
X RState = 0;
X break;
X }
X }
X
X {
X static short ExpAry[] = { 3, 2, 1, 4, 3, 2, 1, 0 };
X
X expect = ExpAry[RState];
X
X if (RState == 7)
X expect = BufLen - DBLen;
X }
X#ifdef NOTDEF
X if (Rto_act) {
X AbortIO((IOR *)&Rto);
X WaitIO((IOR *)&Rto);
X Rto_act = 0;
X }
X if (RState == 7) {
X Rto.tr_time.tv_secs = 8;
X Rto.tr_time.tv_micro= 0;
X SendIO((IOR *)&Rto);
X Rto_act = 1;
X }
X#endif
X do_cmd((uword)-1, NULL, 0);
X return((int)expect);
X}
X
END_OF_FILE
if test 6388 -ne `wc -c <'unix/dnet/packet.c'`; then
echo shar: \"'unix/dnet/packet.c'\" unpacked with wrong size!
fi
# end of 'unix/dnet/packet.c'
fi
if test -f 'unix/lib/dnetlib.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'unix/lib/dnetlib.c'\"
else
echo shar: Extracting \"'unix/lib/dnetlib.c'\" \(6103 characters\)
sed "s/^X//" >'unix/lib/dnetlib.c' <<'END_OF_FILE'
X
X/*
X * DNETLIB.C
X *
X * DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved
X *
X * Library Interface for DNET.
X */
X
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <fcntl.h>
X#include <signal.h>
X#include <stdio.h>
X#include <errno.h>
X#ifdef O_CREAT
X#include <sys/file.h>
X#endif
X#include "../lib/dnetlib.h"
X
Xextern char *getenv();
X
Xtypedef unsigned short uword;
Xtypedef unsigned long ulong;
Xtypedef unsigned char ubyte;
Xtypedef struct sockaddr SOCKADDR;
X
Xtypedef struct {
X int s;
X uword port;
X} CHANN;
X
X#define NAMELEN sizeof(".PORT.XXXXX")
X#define NAMEPAT "%s.PORT.%ld"
X
Xchar *getdirpart();
X
XCHANN *
XDListen(port)
Xuword port;
X{
X CHANN *chan;
X int s;
X SOCKADDR *sa = (SOCKADDR *)malloc(sizeof(SOCKADDR)+256);
X char *dirstr = getenv("DNETDIR") ? getenv("DNETDIR") : "";
X
X sprintf(sa->sa_data, NAMEPAT, dirstr, port);
X sa->sa_family = AF_UNIX;
X unlink(sa->sa_data);
X
X s = socket(PF_UNIX, SOCK_STREAM, 0);
X fcntl(s, F_SETOWN, getpid());
X if (bind(s, sa, sizeof(*sa)-sizeof(sa->sa_data)+strlen(sa->sa_data)) < 0) {
X close(s);
X free(sa);
X return(NULL);
X }
X if (listen(s, 5) < 0) {
X close(s);
X unlink(sa->sa_data);
X free(sa);
X return(NULL);
X }
X chan = (CHANN *)malloc(sizeof(CHANN));
X chan->s = s;
X chan->port = port;
X free(sa);
X return(chan);
X}
X
X
XDUnListen(chan)
XCHANN *chan;
X{
X char *dirstr = getenv("DNETDIR") ? getenv("DNETDIR") : "";
X char buf[32];
X
X close(chan->s);
X sprintf(buf, NAMEPAT, dirstr, chan->port);
X unlink(buf);
X free(chan);
X}
X
XDAccept(chan)
XCHANN *chan;
X{
X SOCKADDR sa;
X int addrlen = sizeof(sa);
X int fd;
X
X fd = accept(chan->s, &sa, &addrlen);
X return(fd);
X}
X
XDOpen(host, port, txpri, rxpri)
Xchar *host;
Xuword port;
Xchar txpri, rxpri;
X{
X int s;
X char rc;
X short xb[3];
X SOCKADDR *sa = (SOCKADDR *)malloc(sizeof(SOCKADDR)+256);
X char *dirstr = getenv("DNETDIR") ? getenv("DNETDIR") : "";
X
X if (rxpri < -127)
X rxpri = -127;
X if (rxpri > 126)
X rxpri = 126;
X if (txpri < -127)
X txpri = -127;
X if (txpri > 126)
X txpri = 126;
X
X if (host == NULL)
X host = (getenv("DNETHOST")) ? getenv("DNETHOST"):"3";
X
X sa->sa_family = AF_UNIX;
X sprintf(sa->sa_data, "%s%s%s", dirstr, "DNET.", host);
X
X s = socket(PF_UNIX, SOCK_STREAM, 0);
X fcntl(s, F_SETOWN, getpid());
X if (connect(s, sa, sizeof(sa->sa_family) + strlen(sa->sa_data)) < 0) {
X close(s);
X free(sa);
X return(-1);
X }
X free(sa);
X xb[0] = port;
X ((char *)&xb[1])[0] = txpri;
X ((char *)&xb[1])[1] = rxpri;
X write(s, xb, 4);
X if (read(s, &rc, 1) == 1 && rc == 0)
X return(s);
X close(s);
X return(-1);
X}
X
XDEof(fd)
X{
X char dummy;
X
X shutdown(fd, 1);
X write(fd, &dummy, 0);
X}
X
Xgwrite(fd, buf, bytes)
Xchar *buf;
X{
X int n;
X int orig = bytes;
X extern int errno;
X while (bytes) {
X n = write(fd, buf, bytes);
X if (n > 0) {
X bytes -= n;
X buf += n;
X continue;
X }
X if (n < 0) {
X if (errno == EINTR)
X continue;
X if (errno == EWOULDBLOCK) {
X int wm = 1 << fd;
X int em = 1 << fd;
X if (select(fd+1, NULL, &wm, &em, NULL) < 0)
X continue;
X if (wm)
X continue;
X }
X return(orig - bytes);
X }
X }
X return(orig);
X}
X
Xgread(fd, buf, bytes)
Xchar *buf;
X{
X int n;
X int orig = bytes;
X extern int errno;
X while (bytes) {
X n = read(fd, buf, bytes);
X if (n > 0) {
X bytes -= n;
X buf += n;
X break;
X }
X if (n < 0) {
X if (errno == EINTR)
X continue;
X if (errno == EWOULDBLOCK) {
X int rm = 1 << fd;
X int em = 1 << fd;
X if (select(fd+1, &rm, NULL, &em, NULL) < 0)
X continue;
X if (rm)
X continue;
X }
X return(orig - bytes);
X }
X if (n == 0)
X break;
X }
X return(orig - bytes);
X}
X
Xggread(fd, buf, bytes)
Xchar *buf;
X{
X int n;
X int ttl = 0;
X while (bytes) {
X n = gread(fd, buf, bytes);
X if (n > 0) {
X bytes -= n;
X buf += n;
X ttl += n;
X continue;
X }
X return(-1);
X }
X return(ttl);
X}
X
X/*
X * Convert to and from 68000 longword format. Of course, it really
X * doesn't matter what format you use, just as long as it is defined.
X */
X
Xntohl68(n)
Xulong n;
X{
X return(
X (((ubyte *)&n)[0] << 24)|
X (((ubyte *)&n)[1] << 16)|
X (((ubyte *)&n)[2] << 8)|
X (((ubyte *)&n)[3])
X );
X}
X
Xhtonl68(n)
Xulong n;
X{
X ulong v;
X ((ubyte *)&v)[0] = n >> 24;
X ((ubyte *)&v)[1] = n >> 16;
X ((ubyte *)&v)[2] = n >> 8;
X ((ubyte *)&v)[3] = n;
X return(v);
X}
X
X
XDoOption(ac, av, ops, args)
Xshort ac;
Xchar *av[];
Xchar *ops;
Xlong args;
X{
X register short i;
X short j;
X
X for (i = j = 1; i < ac; ++i) {
X register char *ptr = av[i];
X if (*ptr != '-') {
X av[j++] = av[i];
X continue;
X }
X while (*++ptr) {
X register char *op;
X long **ap = (long **)&args;
X short isshort;
X
X for (op = ops; *op && *op != *ptr;) {
X if (*op == *ptr)
X break;
X if (*++op == '%') {
X while (*op && *op != 's' && *op != 'd')
X ++op;
X if (*op)
X ++op;
X }
X if (*op == ',') /* optional , */
X ++op;
X ++ap;
X }
X if (*op == 0)
X return(-1);
X if (op[1] != '%') {
X *(short *)*ap = 1;
X ++ap;
X continue;
X }
X op += 2;
X isshort = 1;
X while (*op && *op != 's' && *op != 'd') {
X switch(*op) {
X case 'h':
X isshort = 1;
X break;
X case 'l':
X isshort = 0;
X break;
X default:
X return(-1);
X }
X ++op;
X }
X switch(*op) {
X case 's':
X if (ptr[1]) {
X *(char **)*ap = ptr + 1;
X ptr = "\0";
X } else {
X *(char **)*ap = av[++i];
X }
X break;
X case 'd':
X if (isshort)
X *(short *)*ap = atoi(++ptr);
X else
X *(long *)*ap = atoi(++ptr);
X while (*ptr >= '0' && *ptr <= '9')
X ++ptr;
X break;
X default:
X return(-1);
X }
X }
X }
X return(j);
X}
X
Xelog(how, ctl, arg)
Xchar *ctl;
Xlong arg;
X{
X char *dir = getenv("DNETDIR");
X FILE *fi;
X char buf[256];
X long dtime;
X
X time(&dtime);
X
X if (!dir)
X dir = "";
X sprintf(buf, "%s%s", dir, "DNET.LOG");
X if (fi = fopen(buf, "a")) {
X strcpy(buf, ctime(&dtime));
X buf[strlen(buf)-1] = 0;
X fprintf(fi, "%s ", buf);
X fprintf(fi, ctl, arg);
X putc('\n', fi);
X fclose(fi);
X }
X if (how == EFATAL)
X exit(1);
X}
X
END_OF_FILE
if test 6103 -ne `wc -c <'unix/lib/dnetlib.c'`; then
echo shar: \"'unix/lib/dnetlib.c'\" unpacked with wrong size!
fi
# end of 'unix/lib/dnetlib.c'
fi
echo shar: End of archive 4 \(of 8\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 8 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
--
Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
Mail comments to the moderator at <amiga-request@cs.odu.edu>.
Post requests for sources, and general discussion to comp.sys.amiga.